import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "@/views/login/index.vue";
import Admin from "@/views/admin/index.vue";
import Desk from "@/views/admin/desk/index.vue";
import Tea from "@/views/admin/tea/index.vue";
import User from "@/views/admin/user/index.vue";
import UserIndex from "@/views/user/index.vue"
import Dash from "@/views/admin/dash.vue";
import Order from "@/views/admin/order/index.vue";
import UserDash from "@/views/user/dash.vue"
import UserRoom from "@/views/user/service/index.vue"
import UserOrder from "@/views/user/order/index.vue"
import UpdateUser from "@/views/user/user/update.vue";
import Register from "@/views/register/index.vue";
Vue.use(VueRouter)

export const constantRouters = [
    {
        path:'/',
        name:'login',
        component: Login
    },
    {
        path:'/register',
        name:'register',
        component: Register
    },
    {
        path:'/adminIndex',
        name:'adminIndex',
        component: Admin,
        redirect: '/user',
        children: [
            {path:'/user',name:'user',component:User},
            {path:'/desk',name:'desk',component:Desk},
            {path:'/tea',name:'tea',component:Tea},
            {path:'/order',name:'order',component:Order}
        ]
    },
    {
        path:'/userIndex',
        name:'userIndex',
        component: UserIndex,
        redirect: '/userDash',
        children: [
            {path: '/userDash',name:'userDash',component: UserDash},
            {path: '/userRoom',name:'userRoom',component: UserRoom},
            {path: '/userOrder',name:'userOrder',component: UserOrder},
            {path: '/updateUser',name:'updateUser',component: UpdateUser}
        ]
    }
];


const router = new VueRouter({
    mode: 'history',
    routes: constantRouters
})

// 解决导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

export default router
